import 'package:azlistview/azlistview.dart';
import 'package:flutter/material.dart';
import 'package:magic_car/util/HttpHelper.dart';

class Insurance_Page extends StatefulWidget {
  final Map param;
  final int type;
  // final String bid;
  Insurance_Page(this.param, this.type);
  @override
  State<StatefulWidget> createState() {
    return new _BrandSelectRouteState(this.param, this.type);
  }
}

class _BrandSelectRouteState extends State<Insurance_Page> {
  // List<CityInfo> _cityList = List();
  // List<CityInfo> _hotCityList = List();
  final Map param;
  final int type;
  _BrandSelectRouteState(this.param, this.type);
  List BrandList = List();
  List hotList = List();
  List<double> heights = List();
  TextEditingController texts = new TextEditingController();
  ScrollController scrollController = new ScrollController();

  int _suspensionHeight = 40;
  int _itemHeight = 50;
  String _suspensionTag = "";

  @override
  void initState() {
    super.initState();
    scrollController.addListener(() {
      double position = scrollController.offset.toDouble();
    });
    if (this.type == 2) {
      BrandList = [
        {'name': '行驶本照片与车辆不符'},
        {'name': '抵押车'},
        {'name': '调表车'},
        {'name': '车架号变更'},
        {'name': '发动机号变更'},
        {'name': '查封/违法车'},
        {'name': '出险人伤/人命'},
        {'name': '其他'},
       ];
    }else
    loadData();
  }

  void loadData() async {
    Map<String, String> map = new Map();
    // map["bid"]=this.bid;
    HttpHelper.post(HttpHelper.API_GetInsurance, (data) async {
      //loadpage.close();
      if (data != null) {
        print(data);
        //Toast.show(data["msg"], context);

        if (data["code"].toString() == "1") {
          List temp = data["info"];
          setState(() {
            BrandList = temp;
          });
        }
      }
    }, params: map);
  }

  Widget layout() {
    List<Widget> tiles = [];
    Widget content;

    for (var item in BrandList) {
      tiles.add(GestureDetector(
        onTap: () {
          param["value"] = item["name"];
          // param["type_id"]=item["id"];
          Navigator.pop(context);
        },
        child: new Container(
            //color: Colors.red,
            height: 50,
            width: double.infinity,
            decoration: new BoxDecoration(
              border: new Border(
                  bottom: BorderSide(width: 1, color: Color(0xffe5e5e5))),

              // borderRadius: new BorderRadius.all(new Radius.circular(20.0)),
            ),
            child: new Padding(
                padding: new EdgeInsets.fromLTRB(10, 0, 0, 0),
                child: new Row(children: <Widget>[
                  Padding(
                      padding: new EdgeInsets.fromLTRB(5, 0, 10, 0),
                      child: Text(item["name"]))
                  //Image.network(item["pic_url"],width: 100,height: 30,)
                ]))),
      ));
    }
    tiles.add(
      Padding(
        padding: new EdgeInsets.fromLTRB(10, 0, 0, 0),
        child: new TextField(
          decoration: new InputDecoration(
            border: InputBorder.none,
            hintText: type==1?'其他保险公司请输入':'其他特殊类型请输入',
          ),
          onChanged: (value) {
             param["value"] = value;
          },
          controller: texts,
          onSubmitted: (va) {
            print(va);
            param["value"] = va;
            Navigator.pop(context);
          },
        ),
      ),
    );

    content = new Padding(
        padding: new EdgeInsets.fromLTRB(10, 0, 10, 10),
        child: new Column(
            children: tiles //重点在这里，因为用编辑器写Column生成的children后面会跟一个<Widget>[]，
            //此时如果我们直接把生成的tiles放在<Widget>[]中是会报一个类型不匹配的错误，把<Widget>[]删了就可以了
            ));
    return content;
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('保险公司'),
        backgroundColor: Colors.white,
        elevation: 0,
        // backgroundColor: Color.fromRGBO(255, 204, 48, 1),
      ),
      body: new ListView(
          controller: scrollController, children: <Widget>[layout()]),
    );
  }
}
